﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;

namespace SSTU.Extensions
{
	public static class StringExtensions
	{
		public static string NormalizeWhitespace(this string str)
		{
			if (string.IsNullOrEmpty(str))
			{
				return str;
			}
			const char whitespace = ' ';
			var builder = new StringBuilder(str.Length);
			for (int i = 0; i < str.Length; i++)
			{
				char currentChar = str[i];
				if ((currentChar != whitespace) ||
					(builder.Length == 0) ||
					(builder[builder.Length - 1] != whitespace))
				{
					builder.Append(currentChar);
				}
			}
			return builder.ToString();
		}
	}
}
